/*
 * @Author: yusha
 * @Date: 2023-06-13 15:33:41
 * @LastEditors: yusha
 * @LastEditTime: 2023-07-11 17:06:35
 * @Description: 接口
 */
import axios from 'axios';
import { message } from 'antd';
import { serviceConfig } from './swaggerServiceConfig';

export interface User {
    loginInfo: {
      userId: string;
      username: string;
    };
    userInfo: {};
    auth: never[];
    token: string;
  }
/** 接口前缀 */
const newConfig = { ...serviceConfig };
/** 获取token */
const getUserInLocal = () => {
    const usrStr = window.localStorage.getItem('user');
    if (!usrStr) return;
    try {
        const user = JSON.parse(usrStr).user as User;
        return user;
    } catch (e) {
        return undefined;
    }
};
const axiosOemPurchase = axios.create({
    baseURL: newConfig.baseURL,
    headers: { 'X-Authtoken': getUserInLocal()?.token }
});

// 返回拦截
axiosOemPurchase.interceptors.response.use(function (response) {
    if (response.data.code === 200 || response.data.code === '0' || response.data.code == 0 || 1===1 ) return response;
    message.error(response.data.message);
    return Promise.reject(response.data.message);
}, function (error) {
    message.error('请求错误：' + String(error));
    return Promise.reject(error);
});


export const creatOrder:any = (data) => {
    return axiosOemPurchase({ url: '/order/createOrder', method: 'POST', data });
};

export const orderProcess = (params) => {
    return axiosOemPurchase({ url: '/order/orderProcess', method: 'POST', params });
};

export const creatProduct:any = (data) => {
    return axiosOemPurchase({ url: '/goods/createProduct', method: 'POST', data });
};

export const deliveryStockOut = (params) => {
    return axiosOemPurchase({ url: '/stockout/deliveryStockOut', method: 'POST', params });
};

export const allotNew = (params) => {
    return axiosOemPurchase({ url: '/purchase/allotNew', method: 'GET', params });
};

export const pkgTransferAndShelve = (params) => {
    return axiosOemPurchase({ url: '/storage/pkgCodeInput', method: 'GET', params });
};

export const getDeliveryTaskInfo = (params) => {
    return axiosOemPurchase({ url: '/stockout/getDeliveryTaskInfo', method: 'GET', params });
};

export const signup = (params) => {
    return axiosOemPurchase({ url: '/user/signup', method: 'POST', params });
}

export const getTestPlan = (params) => {
    return axiosOemPurchase({ url: '/tool/testPlan', method: 'GET', params });
}

export const mobileSignup = (params) => {
    return axiosOemPurchase({url: '/user/mobileSignup', method: 'POST', params});
}

export const manualReconciliationCallback = (params) => {
    return axiosOemPurchase({ url: '/purchase/abnormal/manualReconciliationCallback', method: 'GET', params });
}

